#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,C,a[1000006],dp[10][100005],b[1000006],g[1000006],cnt,f[100005],ans=LONG_LONG_MAX,opt,sum;
signed main(){
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>n>>C;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		if(a[i]<a[i-1]) opt=1;
	}
	if(C==0){cout<<0;return 0;}
	if(opt==0){
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]!=a[i+1]){
				ans=min(ans,a[i]*i-sum+C*(n-i));
			}
		}
		cout<<ans;
		return 0;
	}
	for(int i=1;i<=n;i++) b[i]=a[i];
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
		if(b[i]!=b[i-1]) g[++cnt]=b[i];
	for(int i=1;i<=cnt;i++){
		if(g[i]>=a[n]) dp[n%2][i]=g[i]-a[n];
		else dp[n%2][i]=C;
	}
	for(int i=n-1;i>=1;i--){
		int T=i%2; f[0]=dp[T^1][1];
		for(int j=1;j<=cnt;j++) dp[T][j]=0,f[j]=min(f[j-1],dp[T^1][j]);
		for(int j=1;j<=cnt;j++){
			if(g[j]>=a[i]) dp[T][j]=g[j]-a[i]+f[j];
			else dp[T][j]=C+f[j];
			// if(g[j]>=a[i]) dp[T][j]=g[j]-a[i]+min(dp[T^1][1~j])
		}
	}
	for(int i=1;i<=cnt;i++) ans=min(ans,dp[1][i]);
	cout<<ans;
	return 0;
}